﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace Nsf.Samples.RetryActivitySample.Infrastructure.Common.FaultDetails
{
    /// <summary>
    /// Перечень ошибок валидации
    /// </summary>
    [DataContract]
    public class ValidationFaultDetails
    {
        [DataMember]
        public List<ValidationFaultDetailsItem> Errors { get; set; }

        public ValidationFaultDetails()
            : this(new List<ValidationFaultDetailsItem>())
        {
        }

        public ValidationFaultDetails(List<ValidationFaultDetailsItem> errors)
        {
            Errors = errors;
        }

        public ValidationFaultDetails(String code, String description)
        {
            Errors = new List<ValidationFaultDetailsItem> { new ValidationFaultDetailsItem { Code = code, Description = description } };
        }

        public override String ToString()
        {
            var result = new StringBuilder();
            result.AppendLine("При валидации объектов обнаружены ошибки:");
            foreach (var error in Errors)
            {
                result.AppendLine(error.ToString());
            }
            return result.ToString();
        }

    }
}
